package com.wc.codeforces.思维.Long_Multiplication;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/6/14 17:04
 * @description https://codeforces.com/problemset/problem/1954/C
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 110;
    static char[] a, b;

    public static void main(String[] args) {
        int T = sc.nextInt();
        while (T-- > 0) {
            a = sc.next().toCharArray();
            b = sc.next().toCharArray();
            int i = 0, n = a.length;
            while (i < n && a[i] == b[i]) i++;
            if (i != n) {
                if (a[i] < b[i]) {
                    char tmp = a[i];
                    a[i] = b[i];
                    b[i] = tmp;
                }
                i++;
                for (; i < n; i++) {
                    char x = a[i], y = b[i];
                    a[i] = (char) Math.min(x, y);
                    b[i] = (char) Math.max(y, x);
                }
            }
            for (i = 0; i < n; i++) out.print(a[i]);
            out.println();
            for (i = 0; i < n; i++) out.print(b[i]);
            out.println();
        }
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
